﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');


FantastPlatform.UI.DirectiveForm = function (config) {
    Ext.apply(this, config);
    var organizationStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/DirectiveViewService.aspx?Action=GetOrganization'
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Name',
            fields: ['Name', 'Id', 'Code']
        }),
        remoteStore: true
    });
    organizationStore.load();

    var organizationComboBox = new Ext.form.ComboBox({
        fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;部门',
        name: 'Organization',
        hiddenName: 'Organization',
        store: organizationStore,
        displayField: 'Name',
        mode: 'local',
        valueField: 'Name',
        allowBlank: false,
        editable: false,
        triggerAction: 'all',
        emptyText: '选择部门',
        readOnly: true,
        anchor: '95%'

    });
    var policeComboBox = new FantastPlatform.CaseManagement.SearchField({
        fieldLabel: '负责人',
        name: 'Name',
        hiddenName: 'LeaderId',
        valueField: 'Name',
        url: "../Service/DirectiveViewService.aspx?Action=SearchPoliceByStation",
        readOnly: true,
        width: 130
    });
    var typeComBox = new Ext.form.ComboBox({
        fieldLabel: '调警类型',
        store: new Ext.data.SimpleStore({
            fields: ['Code', 'Ttext'],
            data: [
                                    ['机关警力遏制街面两抢发案', '机关警力遏制街面两抢发案'],
                                    ['巡警强化街面整体防控', '巡警强化街面整体防控'],
                                    ['派出所高峰复杂区域防控', '派出所高峰复杂区域防控'],
                                    ['派出所遏制入室盗高发防控', '派出所遏制入室盗高发防控'],
                                    ['派出所遏制机动车盗抢防控', '派出所遏制机动车盗抢防控'],
                                    ['派出所临时治安检查点防控', '派出所临时治安检查点防控']
          ]
        }),
        name: 'Code',
        value: '',
        id: 'module',
        mode: 'local',
        valueField: 'Code',
        triggerAction: 'all',
        displayField: 'Ttext',
        allowBlank: false,
        readOnly: true,
        anchor: '100%'
    });
    this.items = [{
        xtype: 'fieldset',
        title: '下达调警单位填写',
        collapsible: true,
        height: 210,
        layout: 'column',
        labelSeparator: '：',
        items: [{
            columnWidth: .5,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;任务名称',
                name: 'Description',
                allowBlank: false,
                blankText: " 任务名称不能为空",
                anchor: '95%'
            })]
        }, {
            columnWidth: .5,
            border: false,
            layout: 'form',
            items: [typeComBox]
        }, {
            columnWidth: .4,
            border: false,
            layout: 'form',
            items: [organizationComboBox]
        }, {
            columnWidth: .32,
            layout: 'form',
            border: false,
            items: [new Ext.form.TextField({
                fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;巡逻地点坐标',
                name: 'Longitude',
                id: 'AddressX',
                readOnly: true,
                allowBlank: false,
                width: 85
            })]
        }, {
            columnWidth: .14,
            layout: 'form',
            border: false,
            items: [new Ext.form.TextField({
                hideLabel: true,
                fieldLabel: '点位坐标',
                name: 'Latitude',
                id: 'AddressY',
                readOnly: true,
                allowBlank: false,
                width: 85
            })]
        }, {
            columnWidth: .14,
            layout: 'form',
            border: false,
            items: [new Ext.Button({
                text: '地图标记',
                id: 'MapBtn',
                handler: function () {
                    openWind("../MapAddress.aspx?longitude=" + Ext.getCmp('AddressX').getValue() + "&latitude=" + Ext.getCmp('AddressY').getValue(), id, '标记执勤地点', 830, 560, 'new_tab');
                }
            })]
        }, {
            columnWidth: .5,
            border: false,
            layout: 'form',
            items: [new FantastPlatform.UI.DateTimeField({
                fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;开始时间',
                allowBlank: false,
                name: 'StartTime',
                timeFormat: 'H:i',
                blankText: " 开始时间不能为空",
                dateFormat: 'Y-m-d'
            })]
        }, {
            columnWidth: .5,
            border: false,
            layout: 'form',
            items: [new FantastPlatform.UI.DateTimeField({
                fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;结束时间',
                allowBlank: false,
                name: 'EndTime',
                timeFormat: 'H:i',
                blankText: " 结束时间不能为空",
                dateFormat: 'Y-m-d',
                anchor: '95%'
            })]
        }, {
            columnWidth: 1,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextArea({
                fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;巡逻区域',
                name: 'Area',
                allowBlank: false,
                blankText: " 巡逻区域不能为空",
                height: 50,
                anchor: '95%'
            })]
        }, {
            columnWidth: 1,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextArea({
                fieldLabel: '任务内容',
                name: 'Task',
                height: 50,
                anchor: '95%'
            })]
        }]
    },
    {
        xtype: 'fieldset',
        title: '执行单位填写',
        collapsible: true, 
        height:180,      
        layout: 'column',
        labelSeparator: '：',
        items: [{
            columnWidth: .4,
            border: false,
            layout: 'form',
            items: [policeComboBox]
        }, {
            columnWidth: .6,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '负责人电话',
                name: 'LeaderTel',               
                anchor: '95%'        
            })]
        }, {
            columnWidth: .4,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '执行部门人数',
                name: 'SelfOrgPersonNum',               
                anchor: '95%'              
            })]
        }, {
            columnWidth: .6,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextArea({
                fieldLabel: '执行部门人员',
                name: 'SelfOrgPersons',            
                anchor: '95%'
               
            })]
        }, {
            columnWidth: .4,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '支援部门人数',
                name: 'OtherOrgPersonNum',
                anchor: '95%'
            })]
        }, {
            columnWidth: .6,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextArea({
                fieldLabel: '支援部门人员',
                name: 'OtherOrgPersons',
                allowBlank: true,
                height: 50,
                 anchor: '95%'
               
            })]
        }]
    }];
    FantastPlatform.UI.DirectiveForm.superclass.constructor.call(this, {
        bodyStyle: 'padding:5px',
        collapsible: true,
        labelAlign: 'right',
        autoScroll: true,
        border: false
    });
};

Ext.extend(FantastPlatform.UI.DirectiveForm, Ext.form.FormPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.DirectiveForm.superclass.onRender.call(this, ct, position);
        if (this.Id && this.Id != 0) {
            this.add(new Ext.form.Hidden({ name: 'Id', value: this.Id }));
            var Form = this.form;
            this.form.load({
                url: '../Service/DirectiveViewService.aspx?Action=Get',
                params: { id: this.Id },
                waitMsg: '正在读取数据...',
                waitTitle: '请稍后...',
                failure: function (form, action) {
                    if (action.failureType != 'client') {
                        showErrorMessage('操作失败', action.result.message, '');
                    }
                },
                success: function (form, action) {

                }
            });
        }
    }
});

